# -*- coding: utf-8 -*-
"""
@author:  yinbing.li(yinbing.li@zillnk.com)
@version: 1.0.0
@file:    leetcode6_N字形变换.py
@time:    2023/4/14 15:27
"""
class Solution:
    def convert(self, s: str, numRows: int) -> str:
        if numRows == 1:
            return s
        lst = ["" for _ in range(numRows)]
        lst_idx, flag = 0, "+"
        # lst_idx, flag = 0, 1
        for i in s:
            lst[lst_idx] += i
            lst_idx = lst_idx + 1 if flag == "+" else lst_idx - 1
            if lst_idx == numRows - 1:
                flag = "-"
            if lst_idx == 0:
                flag = "+"

            # lst_idx += flag
            # if lst_idx == 0 or lst_idx == numRows - 1:
            #     flag = -flag
        return "".join(lst)

s = Solution()
s.convert("PAYPALISHIRING", 4)